package org.dromara.system.mq;

import org.dromara.common.core.utils.DateUtils;
import org.dromara.system.domain.mq.OrderCallbackParam;
import org.dromara.system.mq.config.OrderQueueConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderCallbackSender {
    private static final Logger log = LoggerFactory.getLogger(OrderCallbackSender.class);

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void sendOrderMessage(OrderCallbackParam param, long delayTime) {
//        log.info("=======发起========延迟回调A端订单状态====================\n发送时间:{}\n发送内容:{}\n{}ms后执行", DateUtils.getDate(), param.getJson().toString(), delayTime);
        try {
            amqpTemplate.convertAndSend(OrderQueueConfig.DELAYED_EXCHANGE_NAME, OrderQueueConfig.DELAYED_CALLA_KEY, param, message -> {
                message.getMessageProperties().setDelayLong(delayTime);
                return message;
            });
        } catch (AmqpException e) {
            log.error("发起【延迟回调A端订单状态】 异常{},{}", getClass(), e.getMessage());
        }
    }

}
